<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use think\Controller;
use think\Db;
use think\Request;
use think\facade\Env;
use think\facade\Session;
// use app\admin\Model\Gkdata;
class Yhtype1 extends Base
{
    public function search()
    {
        $request=new request();
        $sname=$request->post('sname');
        $yid=(int)$sname;
        // dump($ptid);exit;
        if(empty($yid)){
            $data=Db::table('yhtype1')->paginate(10);
        }else{
            $data=Db::table('yhtype1')->where('yid',$yid)->paginate(10);
        }
        $this->assign('data',$data);
        return $this->fetch('index');
    }
    public function lookyh(){
        $request=new request();
        $yid=$request->get('id');
        if($yid!=0||!empty(yid)){
            $data=Db::table('yhtype1')->where('yid',$yid)->paginate(10);
        }else{
            $this->error('该拼团还没有选择优惠方式','ptzq/index');
        }
        $this->assign('data',$data);
        return $this->fetch('index');
    }
    public function index()
    {
        $data=Db::table('Yhtype1')->paginate(10);
        $this->assign('data',$data);
        return $this->fetch();
    }

    // 进入
    public function addpage(){
        return $this->fetch();
    }
    // 添加
    public  function addad(){
        // $adxm1=Session::get('adxm');
        $request=new request();
        $yname = $request->post("yname");
        $yhman = $request->post("yhman");
        $yhzk = $request->post("yhzk");
        $data1=[
            "yname"=>$yname,
            "yhman"=>$yhman,
            "yhzk"=>$yhzk,
            "time"=>time()
        ];
        $re=Db::name('yhtype1')->insert($data1);
        if($re){
            $this->success('新增优惠方式成功', 'yhtype1/index');
        }else{
            return $this->error('新增优惠方式失败');
        }
    }
    // 进入更改优惠
    public function editpage(){
        $request=new request();
        $id= intval($request->get("id"));
        $data=Db::name('yhtype1')->where('yid',$id)->find();       
        $this->assign('data',$data);
        return $this->fetch();
    }
    // 审核优惠
    
    // 更改优惠
    public  function editad(){
        $request=new request();
        $data1=[];
        $yid=$request->post('yid');
        $data1['yid']=$yid;
        $data=Db::name('yhtype1')->where('yid',$yid)->find();
        $yname = $request->post("yname");
        if($yname!=$data['yname']){
            $data1['yname']=$yname;
        }
        $yhman = $request->post("yhman");
        if($yhman!=$data['yhman']){
            $data1['yhman']=$yhman;
        }
        $yhzk = $request->post("yhzk");
        if($yhzk!=$data['yhzk']){
            $data1['yhzk']=$yhzk;
        }
        $data1['time']=time();
        $da=Db::name('yhtype1')->update($data1);
        if($da){
            $this->success('更新优惠成功', 'yhtype1/index');
        }else{
            return $this->error('更新优惠失败');
        }

    }
    // 删除用户
    public function delyhtype()
    {

        $request=new request();
        $adid=$request->get("id");
        $da=Db::name('yhtype1')->delete($adid);
        if($da){
            $this->success('删除成功', 'yhtype1/index');
        }
        else{
            return $this->error('删除失败');
        }
    }




}
